﻿using System;
using System.ServiceModel.Channels;
using System.ServiceModel.Description;
using System.ServiceModel.Dispatcher;

namespace Granite.Wcf.Debugging
{
	/// <summary>
	/// Use this for examining how the interface works.
	/// </summary>
	public class DebugOperationBehaviorAttribute : DebugAttribute, IOperationBehavior
	{
		/// <summary>
		/// Implement to pass data at runtime to bindings to support custom behavior.
		/// </summary>
		/// <param name="operationDescription">
		/// The operation being examined. Use for examination only. If the operation description is modified, the results are undefined.
		/// </param>
		/// <param name="bindingParameters">
		/// The collection of objects that binding elements require to support the behavior.
		/// </param>
		public void AddBindingParameters(OperationDescription operationDescription, BindingParameterCollection bindingParameters)
		{
			WriteLine(string.Format("IOperationBehavior.AddBindingParameters: operationDescription=\"{0}\"", operationDescription.Name));
		}

		/// <summary>
		/// Implements a modification or extension of the client across an operation.
		/// </summary>
		/// <param name="operationDescription">
		/// The operation being examined. Use for examination only. If the operation description is modified, the results are undefined.
		/// </param>
		/// <param name="clientOperation">
		/// The run-time object that exposes customization properties for the operation described by <paramref name="operationDescription" />.
		/// </param>
		public void ApplyClientBehavior(OperationDescription operationDescription, ClientOperation clientOperation)
		{
			WriteLine(string.Format("IOperationBehavior.ApplyClientBehavior: operationDescription=\"{0}\" clientOperation=\"{1}\"", operationDescription.Name, clientOperation.Name));
		}

		/// <summary>
		/// Implements a modification or extension of the service across an operation.
		/// </summary>
		/// <param name="operationDescription">
		/// The operation being examined. Use for examination only. If the operation description is modified, the results are undefined.
		/// </param>
		/// <param name="dispatchOperation">
		/// The run-time object that exposes customization properties for the operation described by <paramref name="operationDescription" />.
		/// </param>
		public void ApplyDispatchBehavior(OperationDescription operationDescription, DispatchOperation dispatchOperation)
		{
			WriteLine(string.Format("IOperationBehavior.ApplyDispatchBehavior: operationDescription=\"{0}\" dispatchOperation=\"{1}\"", operationDescription.Name, dispatchOperation.Name));
		}

		/// <summary>
		/// Implement to confirm that the operation meets some intended criteria.
		/// </summary>
		/// <param name="operationDescription">
		/// The operation being examined. Use for examination only. If the operation description is modified, the results are undefined.
		/// </param>
		public void Validate(OperationDescription operationDescription)
		{
			WriteLine(string.Format("IOperationBehavior.Validate: operationDescription=\"{0}\"", operationDescription.Name));
		}

	}

}
